add gnu attributes to addtional printf like functions (#1088)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Wed, 26 Apr 2023 23:02:18 +0000 (17:02 -0600)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2023 23:02:18 +0000 (17:02 -0600)
* add gnu attribute for format string checks on additional functions.

* silence msvc whining about unknown attributes.

In c++17 unknown attributes should be ignored without causing an error.
But these warnings are excessive:
"warning C5030: attribute 'gnu::format' is not recognized"

CMakeLists.txt
defs.h
gbfile.h

index 505e306f913660ec49205a93d8c6f9632096503f..664e662fdc598f902c5161e8b88ad7dfae5f32eb 100644 (file)
@@ -310,7 +310,7 @@ endif()
 if(MSVC)
   target_compile_definitions(gpsbabel PRIVATE _CRT_SECURE_NO_WARNINGS)
   target_compile_definitions(gpsbabel PRIVATE _CRT_NONSTDC_NO_WARNINGS)
-  target_compile_options(gpsbabel PRIVATE /MP -wd4100 -wd4267)
+  target_compile_options(gpsbabel PRIVATE /MP -wd4100 -wd4267 -wd5030)
 endif()
 
 if(APPLE)
diff --git a/defs.h b/defs.h
index f2e67f490218dcdb2c080bb1bd0db99bc49a750c..674ead1b724b7cd2e82eab8f10208da78412f1a9 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1021,7 +1021,7 @@ int str_match(const char* str, const char* match);
 [[gnu::format(printf, 2, 3)]] int xasprintf(char** strp, const char* fmt, ...);
 [[gnu::format(printf, 2, 3)]] int xasprintf(QString* strp, const char* fmt, ...);
 [[gnu::format(printf, 2, 3)]] int xasprintf(QScopedPointer<char, QScopedPointerPodDeleter>& strp, const char* fmt, ...);
-int xvasprintf(char** strp, const char* fmt, va_list ap);
+[[gnu::format(printf, 2, 0)]] int xvasprintf(char** strp, const char* fmt, va_list ap);
 char* strupper(char* src);
 char* strlower(char* src);
 time_t mklocaltime(std::tm* time);
index 24be29378f6f073b15dcd534001ede44a731ff36..a2f7257e9da70b251fdef1dee597b7f5ea103a70 100644 (file)
--- a/gbfile.h
+++ b/gbfile.h
@@ -104,8 +104,8 @@ QByteArray gbfreadbuf(gbsize_t size, gbfile* file);
 int gbfgetc(gbfile* file);
 QString gbfgets(char* buf, int len, gbfile* file);
 
-int gbvfprintf(gbfile* file, const char* format, va_list ap);
-int gbfprintf(gbfile* file, const char* format, ...);
+[[gnu::format(printf, 2, 0)]] int gbvfprintf(gbfile* file, const char* format, va_list ap);
+[[gnu::format(printf, 2, 3)]] int gbfprintf(gbfile* file, const char* format, ...);
 int gbfputc(int c, gbfile* file);
 int gbfputs(const QString& s, gbfile* file);
 int gbfwrite(const void* buf, gbsize_t size, gbsize_t members, gbfile* file);